package com.juneng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.Condition;
import com.juneng.entity.CourseLog;
import com.juneng.mapper.CourseLogMapper;
import com.juneng.service.ICourseLogService;
import com.juneng.dto.CourseLogDto;
import com.juneng.dto.CourseLogQueryDto;
import com.juneng.utils.BeanCopyUtils;
import com.juneng.vo.CourseLogVo;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * 课程观看记录表 服务实现类
 *
 * @author zds
 * @since 2021-07-08
 */
@Service
@AllArgsConstructor
public class CourseLogServiceImpl implements ICourseLogService {

    protected CourseLogMapper courseLogMapper;
    @Override
    public IPage<CourseLogVo> page(CourseLogQueryDto dto) {
        IPage<CourseLogVo> page = Condition.getPage(dto);
        return courseLogMapper.page(page,dto);
    }

    @Override
    public List<CourseLog> list(CourseLogQueryDto dto) {
        QueryWrapper<CourseLog> queryWrapper = new QueryWrapper<>(BeanCopyUtils.copy(dto,CourseLog.class));
        return courseLogMapper.selectList(queryWrapper);
    }

    @Override
    public Integer save(CourseLogDto dto) {
        return courseLogMapper.insert(BeanCopyUtils.copy(dto,CourseLog.class));
    }

    @Override
    public Integer updateById(CourseLogDto dto) {
        return courseLogMapper.updateById(BeanCopyUtils.copy(dto,CourseLog.class));
    }

    @Override
    public Integer deleteLogic(List<Integer> toIntList) {
        return courseLogMapper.deleteBatchIds(toIntList);
    }

    @Override
    public CourseLog getById(Integer id) {
        return courseLogMapper.selectById(id);
    }
}
